package com.zit.java.service.menu;

import com.zit.java.dao.SysMenuMapper;
import com.zit.java.pojo.SysMenu;
import com.zit.java.util.object.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
//service 操作数据库
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    @Transactional
    public List<SysMenu> queryAllMenu() {
     List<SysMenu> list =    sysMenuMapper.queryAll();
         TableData td = new TableData();
//        td.setCode(200);
//        td.setMsg("s失败");
//        td.setCount(list.size());
         td.setData(list);
         return list;
    }

    @Override
    public int saveMenu(SysMenu sysMenu) {
       int res = sysMenuMapper.insertSelective(sysMenu);
        return res;
    }

    @Override
    public int deleteMenu(int meunId) {
        int rst = sysMenuMapper.deleteByPrimaryKey(meunId);
        return rst;
    }





    @Override
    public int deleteMenuBatch(String[] mIds) {
       int b =  sysMenuMapper.deleteByPrimaryKeyBatch(mIds);
        return b;
    }

    @Override
    public int updateMenu(SysMenu sysMenu) {
     int rst =   sysMenuMapper.updateByPrimaryKeySelective(sysMenu);
        return rst;
    }

    @Override
    public SysMenu selectByMenuId(Integer menuId) {
      SysMenu sysMenu =  sysMenuMapper.selectByPrimaryKey(menuId);
        return sysMenu;
    }

    /**
     * 通过菜单名查询菜单
     *
     * @param menuName
     * @return
     */
    @Override
    public List<SysMenu> queryMenuByMenuName(String menuName) {
      List<SysMenu> lsit=   sysMenuMapper.queryMenuByMenuName(menuName);
        return lsit;
    }


}
